<template>
  <div style="margin-bottom: 20px;">
    <el-dialog :title="edit_main_title" append-to-body v-dialogDrag :visible.sync="edit_flag"
               width="800px"  @open="handleOpenConfig" :before-close="handleClose">
      <!-- 表单 -->
      <el-form label-width="120px" ref="objEditFrom" class="web_form_two"
               :rules="objEditRules" :model="objEditData" :disabled="editMakeDisabled">
        <el-form-item label="系统运单号" prop="orderRleaseGid">
          <el-input type="textarea" :rows="2" style="width: 250px" clearable v-model="objEditData.orderRleaseGid" class="w184"></el-input>
        </el-form-item>
        <el-form-item label="是否异常可发运" prop="isCanSend">
          <el-select class="w184" v-model="objEditData.isCanSend" clearable filterable remote reserve-keyword placeholder="请选择状态">
            <el-option key="1" label="不可发运" value="N"></el-option>
            <el-option key="2" label="可发运" value="Y"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理时间" prop="estimatedProcessingTime">
          <el-date-picker
            class="w184"
            v-model="objEditData.estimatedProcessingTime"
            type="datetime" clearable
            :picker-options="pickerOptions"
            value-format='yyyy-MM-dd HH:mm:ss'
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="异常原因" prop="exceptionReason">
          <el-input type="textarea" :rows="2" style="width: 250px" clearable v-model="objEditData.exceptionReason" class="w184"></el-input>
        </el-form-item>
      </el-form>
      <!--按钮-->
      <el-row type="flex" justify="end">
        <!--<el-button type="primary" @click="handleClose">关闭</el-button>-->
        <el-button class="mr30" v-if="edit_main_title !== '查看'" type="primary" @click="confirmClick">提交</el-button>
      </el-row>
      <div style="height:20px"></div>
    </el-dialog>
  </div>
</template>

<script>
  import * as ExceptionAPI from '@/api/pick/exception'
  // import * as Utils from '@/utils/index'
  export default {
    name: '',
    props: ['edit_flag', 'edit_main_title', 'edit_select_row', 'edit_params'],
    components: {},
    data() {
      return {
        objEditData: {
          orderRleaseGid: '', // 系统运单号（大文本框）
          exceptionReason: '', // 异常原因
          isCanSend: '', // 是否异常可以发运（N为不可发，Y为可发）
          houseId: '', // 获取当前仓库houseId
          estimatedProcessingTime: '' // 预计处理完成时间（时间做判断。不能早于当前时间，不能晚于当前时间30天）
        },
        objEditRules: {
          orderRleaseGid: [{ required: true, message: '请选择', trigger: 'change' }],
          exceptionReason: [{ required: true, message: '请选择', trigger: 'change' }],
          isCanSend: [{ required: true, message: '请选择', trigger: 'change' }],
          estimatedProcessingTime: [{ required: true, message: '请选择', trigger: 'change' }]
        },
        makeInputDisabled: false, // -input 禁用
        editMakeDisabled: false, // 面板禁用
        pickerOptions: {
          disabledDate: (time) => {
            return time.getTime() < (Date.now() - 8.64e7) || time.getTime() > (Date.now() + 3600 * 1000 * 24 * 30)
          }
        }
      }
    },
    methods: {
      // 弹窗页打开初始
      handleOpenConfig(data) {
        const that = this
        console.log(that.$props.edit_main_title, 'that.$props', that.$props.edit_select_row, that.$props.edit_params)
        // const { code, masslossStatus, creator, treatmentTime } = that.$props.edit_select_row // attachmentId
        // const myDate = Utils.parseTime(Date.now(), '{y}-{m}-{d} {h}:{i}:{s}')
        // 重置
        that.editMakeDisabled = false
        that.makeInputDisabled = false
        that.objEditData = {
          orderRleaseGid: '', // 系统运单号（大文本框）
          exceptionReason: '', // 异常原因
          isCanSend: '', // 是否异常可以发运（N为不可发，Y为可发）
          houseId: '', // 获取当前仓库houseId
          estimatedProcessingTime: ''
        }
        // 查看 新增 编辑
        if (that.$props.edit_main_title === '新增') {
          // that.getSelectListFunc()
        } else if (that.$props.edit_main_title === '编辑') {
          that.objEditData = { }
          // that.getSelectListFunc()
          that.editMakeDisabled = false
          that.makeInputDisabled = true
        } else if (that.$props.edit_main_title === '查看') {
          that.objEditData = { }
          that.editMakeDisabled = true
        }
      },
      // 条件列表查询
      getMasslossCodeListFunc(val) {
        // ExceptionAPI.getMasslossCode({ code: val }).then(res => {
        //   this.masslossCodeList = res.data
        // }).catch(err => {
        //   console.log('error', err)
        // })
      },
      // 选择 设置名称导出 $event,scope.row,'modelNo'
      selectCorp($event, value) {
        console.log('selectCorp(value)', $event, value)
        // const that = this
        // if (value === 'driverName') {
        //   that.fleetList.map(item => {
        //     if ($event === item.name) {
        //       that.objEditData.driverPhone = item.mobile
        //       that.objEditData.transportationId = item.plate
        //     }
        //   })
        // }
      },
      // 提交
      confirmClick() {
        const that = this
        that.$refs['objEditFrom'].validate((valid) => {
          if (valid) {
            // const { masslossCode, masslossStatus, creator, treatmentTime } = that.objEditData
            // const toParams = { masslossCode, masslossStatus, creator, treatmentTime: Date.parse(treatmentTime) }
            that.objEditData.houseId = that.$store.getters.currentStorehouse.id
            if (that.$props.edit_main_title === '新增') {
              ExceptionAPI.saveException(that.objEditData).then(res => {
                that.$message({
                  message: '新增成功',
                  type: 'success',
                  duration: 2000
                })
                that.$emit('edit-confirm', false)
              }).catch(err => {
                console.log('error', err)
              })
            }
          }
        })
      },
      handleClose() {
        this.$emit('edit-close', false)
      }
    }
  }
</script>

<style scoped>
</style>
